﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

namespace QLZ_For_Csharp_Demo
{
    class Program
    {
        static FileStream defstream;
        static byte[] fifo = new byte[4096];

        static void data_callback(int block_len)
        {
            defstream.Write(fifo, 0, block_len);
        }

        static void PressFile(string src_path, string dst_path)
        {
            byte[] src_file = File.ReadAllBytes(src_path);
            int len = src_file.Length;
            byte[] dst_file = new byte[len];
            QLZ_Interface.QLZ_Compress(src_file, dst_file, ref len);
            using (FileStream fstream = File.Create(dst_path))
            {
                fstream.Write(dst_file, 0, len);
            }
        }

        static void DepressFile(string src_path, string dst_path)
        {
            byte[] src_file = File.ReadAllBytes(src_path);
            int len = src_file.Length;
            defstream = File.Create(dst_path);
            QLZ_Interface.QLZ_Decompress(src_file, len, fifo, data_callback);
            defstream.Close();
        }

        static void Main(string[] args)
        {
            string press_src_file = "press_src.bin";
            string press_dst_file = "press_dst_ot.bin";
            string depress_src_file = "press_dst_ot.bin";
            string depress_dst_file = "depress_dst_ot.bin";

            PressFile(press_src_file, press_dst_file);
            DepressFile(depress_src_file, depress_dst_file);
        }
    }
}
